package com.winning.hashmap;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class Lambda {


    public static void main(String[] args) {

        List<Integer> lists = new ArrayList<>();
        lists.add(1);
        lists.add(5);
        lists.add(2);
        lists.add(6);
        lists.add(9);
        lists.add(3);
        lists.add(7);

        Optional<Integer> optional = lists.stream().min(Integer::compareTo);
        if(optional.isPresent()){
            System.out.println(optional.get());
        }
        System.out.println("------------------------------");

        lists.stream().max(Integer::compareTo).ifPresent(System.out::println);
        System.out.println("------------------------------");

        lists.stream().sorted().forEach(ele ->{
            System.out.println(ele);
        });
        System.out.println("------------------------------");

        lists.stream().filter(ele-> ele>3).forEach(ele -> System.out.println(ele));
        System.out.println("------------------------------");

        lists.stream().filter(ele-> ele > 2).filter(ele -> ele <7).forEach(ele -> System.out.println(ele));
        System.out.println("------------------------------");

        int sum = lists.stream().reduce(0,(a,b) -> a+b);
        System.out.println(sum);
        System.out.println("------------------------------");

        int result = lists.stream().reduce(1,(a,b) -> a*b);
        System.out.println(result);
        System.out.println("------------------------------");

    }

}
